﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CWY.Data;
using CWY.Model;
using CWY.Entities;
using CWY.Data.IRepository;
using CWY.Data.Repository;

namespace CWY.Domain.Handlers
{
    public class AccountHandler
    {
        IAccountRepository _repository = new AccountRepository();

        public void AddAccount(Account _account)
        {
            try
            {
                _repository.AddAccount(new CWY.Entities.tbl_account()
                {
                    account_id = Guid.NewGuid(),
                    account_firstname = _account.Firstname,
                    account_lastname = _account.Lastname,
                    account_displayname = _account.DisplayName,
                    account_dob = _account.DOB,
                    account_email = _account.Email,
                    account_password = _account.Password,
                    account_is_active = _account.IsActiveUser,
                    account_creationdate = DateTime.Now,
                    account_modifiedate = DateTime.Now
                });
            }
            catch (Exception ex) { }
        }

        public IEnumerable<Account> GetAccounts()
        {
            try
            {
                return _repository.GetAccounts().Select(m => new Account()
                {
                    Firstname = m.account_firstname,
                    Lastname = m.account_lastname,
                    DisplayName = m.account_displayname,
                    DOB = (DateTime)m.account_dob,
                    Email = m.account_email,
                    Password = m.account_password,
                    IsActiveUser = Convert.ToBoolean(m.account_is_active)
                }).ToList<Account>();
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}
